/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: Pegasus  Date: 2019-02-13 Time: 23:07
 */



import {Action} from "../../../configuration/ActionCreator"
import {FetchStatus, RequestAction, RequestMethod} from "../../../configuration/RequestConfiguration";
import {AppRequestPath} from "../../../configuration/AppConfig";
import {API_PROCEDURE2} from "../../../constant/API";
import global from "../../../configuration/global";
import {procHoReservationDefault, procRetrieveRoomsViewAs} from "../../../request/RoomsViewRequest";

/**
 * 获取数据
 * @str {string}
 * @page {int}页数
 */
export const WorkOrderList = 'WorkOrderList';
export const getDs = (str) => {
    let action = Action(WorkOrderList);
    return dispatch => dispatch(requestGetDs(action, str))
}

export const requestGetDs = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKOrderSweepByUserid',
            'jn': str,
            'jnJson2': {"output":{"json":"no"}}
        },
        action
    )
};

export const onOrderScreenDs = (state = {}, action) => {
    switch (action.type) {
        case WorkOrderList: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};



/**
 * 获取数据
 */
export const RetrieveRoomsView = 'RetrieveRoomsView';
export const RetrieveRoomsViewAs = (str) => {
    let action = Action(RetrieveRoomsView);
    return dispatch => dispatch(procRetrieveRoomsViewAs(action, str))
}


/**
 * 获取不显示图标
 */
export const ReservationDefault = 'ReservationDefault';
export const HoReservationDefault = (str) => {
    let action = Action(ReservationDefault);
    return dispatch => dispatch(procHoReservationDefault(action, str))
}



// ----------------------------新建赶房-------------------------------
// WHSKDailyOrderSweepSave
export const OrderSweepSave = 'OrderSweepSave';
export const orderSweepSave = (str) => {
    let action = Action(OrderSweepSave);
    return dispatch => dispatch(requestOrderSweepSave(action, str))
}

export const requestOrderSweepSave = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKDailyOrderSweepSave',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onOrderSweepSave = (state = {}, action) => {
    switch (action.type) {
        case OrderSweepSave: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

//------------------------------新建退房检查----------------------------------

export const OrderCheckOutSave = 'OrderCheckOutSave';
export const orderCheckOutSave = (str) => {
    let action = Action(OrderCheckOutSave);
    return dispatch => dispatch(requestOrderCheckOutSave(action, str))
}

export const requestOrderCheckOutSave = (action, str) => {
    return RequestAction(
        AppRequestPath() + API_PROCEDURE2,
        RequestMethod.Post,
        {
            'hotelId': global.hotelId,
            'fu': 'WHSKOrderCheckoutInspectSave',
            'jn': str,
            'jnJson2': JSON.stringify({}),
        },
        action
    )
};

export const onOrderCheckOutSave = (state = {}, action) => {
    switch (action.type) {
        case OrderCheckOutSave: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state , fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json , fetchStatus: action.status}
                }
                default: {
                    return {...state , fetchStatus: action.status}
                }
            }
        }
    }
    return state
};
